﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace COFE.Core.Actions
{
    public class TimerSchedule : ScheduleBase
    {
        public TimerSchedule(WorkPriority priority, DateTime startTimeUtc, IWork work)
            : base(priority, work)
        {
            if (priority == WorkPriority.NotReady)
                throw new ArgumentException();
            _startTimeUtc = startTimeUtc;
        }

        #region Methods

        public void Cancel()
        {
            _cancelled = true;
        }

        #endregion

        #region Data

        private DateTime _startTimeUtc;
        private bool _cancelled = false;

        #endregion

        #region Public Properties

        public override WorkPriority Priority
        {
            get
            {
                if (_cancelled)
                    return WorkPriority.Cancelled;

                return DateTime.UtcNow > _startTimeUtc ?
                    base.Priority : WorkPriority.NotReady;
            }
            protected set { base.Priority = value; }
        }


        public override bool IsFinished { get { return Priority != WorkPriority.NotReady; } }        

        #endregion




    }
}
